
        var token;
        var currentTabIndex; 
        var PCD;
        var PCD2;
        var json;
        var json2;
        var jjdz11;
        var jjdz12;
        var currentTabIndex2;
        var newdata = [];
        var json22 = [{
                "jiJianGongSiMingCheng": $("#jiJianGongSiMingCheng2").val(),
                "jiJianRenDiZhi1": $("#jiJianRenDiZhi100").val(),
                "jiJianRenDiZhi2": $("#jiJianRenDiZhi22").val(),
                "jiJianRenDiZhi3": $("#jiJianRenDiZhi33").val(),
                "jiJianRenDianHua": $("#jiJianRenDianHua2").val(),
                "jiJianRenMingCheng": $("#jiJianRenMingCheng2").val(),
        }];
        //填充lastStep页面内容
        function lastStep(id1,class1,index1) {
            var params = {
                'apiKey': 'api_post_getContactUs',
                'deviceType': 'DIC_DEVICE_TYPE_1',
                contentType: "application/json;charset=utf-8",
                datatype: 'json'
            };
            $(id1 + ' li:eq('+(index1)+') a').tab('show');
            if(id1 == "#rootwizard") {
                $('.show_name').text($('#jiJianRenMingCheng').val());
                $('.show_phone').text($('#jiJianRenDianHua').val());
                $('.show_address').text($('#jiJianRenDiZhi10').val());
                $('.show_name2').text($('#shouJianRenXingMing').val());
                $('.show_phone2').text($('#shouJianRenShouJi').val());
                $('.show_address2').text($('#stateId').val()+', '+$("#countryId").find("option:selected").text());
            }
            //获取手机号字段
            ajax('post', '/d_easy/deasy/api', params, 'json', function(data) {
                var reg = /(?:\+?86)?1(?:3\d{3}|5[^4\D]\d{2}|8\d{3}|7(?:[235-8]\d{2}|4(?:0\d|1[0-2]|9\d))|9[0135-9]\d{2}|66\d{2})\d{6}/;
                var data = data.contactUs.content;
                var phone =  data.match(/(?:\+?86)?1(?:3\d{3}|5[^4\D]\d{2}|8\d{3}|7(?:[235-8]\d{2}|4(?:0\d|1[0-2]|9\d))|9[0135-9]\d{2}|66\d{2})\d{6}/,"")[0];
                $(class1).text(phone);
            })
        }
        //获取当前tab标签索引
        function getCurrentTabIndex(id1) {
            var $tabs = $(id1).children('li');
            var i=0;
            $tabs.each(function() {
                var $tab = $(this);
                if($tab.hasClass('active')) {
                    return false;
                } else {
                    i++;
                }
            })
            return i;
        };
        //禁用最后一步提交
        function disable(class1,boole1,val1,num1) {
            $(class1 + " .next a").attr("disabled",boole1).css("pointer-events",val1);
            $(class1 + " .next a").css({ opacity: num1});
        }
        //创建订单
        function yundans(subdata,id1,index1,class1) {
            token = sessionStorage.getItem("token");
            var headers = {
                'Content-Type': "application/json",
                'Authorization': token
            };
            $.ajax({
                url: "http://lex.itdida.com/itdida-api/yundans",
                type: "post",
                headers: headers,
                data: JSON.stringify(subdata),
                dataType: 'json',
                success: function (data) {
                    if (data.data[0].code == 200 || data.data[0].code == 303) {
                        $(id1 + ' li:eq('+(index1+1)+') a').tab('show');
                        $(class1 + " .previous," + class1 + " .next").hide();
                        console.log(data);
                    } else {
                        console.log(data);
                        alert(data.data[0].message);
                    }
                    disable(class1,false,"auto",1)
                },
                error: function(data) {
                    alert(jQuery.parseJSON(data.responseText).data);
                    disable(class1,false,"auto",1)
                }
            })
        }
        //《违禁产品声明》弹层
        function orderTerms(class1) {
            layer.open({
                type: 2,
                title: ['国际运输中哪些货物不能寄运', 'font-size:18px;color:#ff0000;text-align:center;'],
                closeBtn: 1,
                area: ['800px', '1200px'],
                shadeClose: true,
                skin: 'btn',
                btn: ['我已阅读该条款,同意并遵守'],
                btnAlign: 'c',
                content: 'order_terms.html',
                yes: function(index, layero) {
                    $(class1 + " input[type='checkbox']").prop("checked", true);
                    layer.close(index);
                }
            });
        }
        //登录框登录成功后调用
        function login() {
            $('#top').attr('src', $('#top').attr('src'));
            if($(".content_title ul.nav li:first").hasClass('active')) {
                yundans(json2,"#rootwizard",currentTabIndex,".djxd")
            } else if($(".content_title ul.nav li:eq(1)").hasClass('active')) {
                yundans(newdata,"#rootwizard2",currentTabIndex2,".plxd");
            }
        }
        //验证地址
        function verifyAddress(id1,class1) {
            var b = $(id1).val();
            $(class1 +" span.tishi").remove();
            if(b == "") {
                if(class1 == ".jjdz11") {
                    jjdz11 = false;
                    $(class1).append("<span class='tishi' style='font-size:12px;color:red;'>请填写所在街道及详细地址</span>");
                }else if(class1 == ".jjdz12") {
                    jjdz12 = false;
                    $(class1).append("<span class='tishi' style='font-size:12px;color:red;'>请填写所在街道及详细地址</span>");
                }else if(class1 == ".PCD") {
                    PCD = false;
                    $(class1).append("<span class='tishi' style='font-size:12px;color:red;'>请选择省市区</span>");
                }else if(class1 == ".PCD2") {
                    PCD2 = false;
                    $(class1).append("<span class='tishi' style='font-size:12px;color:red;'>请选择省市区</span>");
                }
            }else{
                if(class1 == ".jjdz11"){
                    jjdz11 = true;
                }else if(class1 == ".jjdz12"){
                    jjdz12 = true;
                }else if(class1 == ".PCD") {
                    PCD = true;
                }else if(class1 == ".PCD2") {
                    PCD2 = true;
                }
            }; 
        }
        //弹出iframe登录框
        function loginBox() {
            layer.open({
                type: 2,
                title: ['递送易登录', 'font-size:18px;color:#000;'],
                closeBtn: 1,
                area: ['542px', '432px'],
                shadeClose: false,
                skin: 'yourclass',
                content: 'loginBox.html',
                yes: function(index, layero) {
                    $("#verify").show();
                },
                cancel: function(index, layero) { 
                    if($(".content_title ul.nav li:first").hasClass('active')) {
                        disable(".djxd",false,"auto",1);
                    } else if($(".content_title ul.nav li:eq(1)").hasClass('active')) {
                        disable(".plxd",false,"auto",1);
                    }
                }
            });
        }
        //返回上一步
        function previous(id1,class1) {
            currentTabIndex = getCurrentTabIndex(id1);
            $(id1 + ' li:eq('+(currentTabIndex-1)+') a').tab('show');
            if (currentTabIndex == 1) {
                $(class1).hide();
            } 
        }
        // function verifyInfo(id1,class1,class2,class3) {
        //     currentTabIndex = getCurrentTabIndex(id1);
        //     if(currentTabIndex == 2 && !($(class1 + " input[type='checkbox']").is(':checked'))) {
        //                 $(id1 + ' li:eq('+(currentTabIndex)+') a').tab('show');
        //                 layer.msg('请勾选《违禁产品声明》',);
        //             } else if (currentTabIndex == 2 && $(class1 + " input[type='checkbox']").is(':checked')) {
        //                 if(token == '' || token == 'undefined' || token == undefined || token == NaN || token == 'NaN') {
        //                     //填充step4信息
        //                     lastStep(id1,class2,currentTabIndex);
        //                     //禁用下一步按钮
        //                     disable(class3,true,"none",0.2);
        //                     //弹出iframe登录框
        //                     loginBox();
        //                 }else{
        //                     lastStep(id1,class2,currentTabIndex);
        //                     disable(class3,true,"none",0.2);
        //                     yundans(json2,id1,currentTabIndex,class3)
        //                 }
        //             }else{
        //                 $(class3 + ".previous").show();
        //                 $(id1 + ' li:eq('+(currentTabIndex+1)+') a').tab('show');
        //             }
        // }
        /**
        * tree 数据转换
        * @param  {Array} tree 待转换的 tree
        * @return {Array}      转换后的 tree
        */
        // function convertTree (tree) {
        //     const result = [];
        //     // 遍历 tree
        //     tree.forEach(function(item) {
        //         // 解构赋值
        //         let {
        //             code: value,
        //             name: label,
        //             children: children
        //         } = item;
        //         // 如果有子节点，递归
        //         if (children) {
        //             children = convertTree(children);
        //         }
        //         result.push({
        //             value,
        //             label,
        //             children
        //         });
        //     });
        //     return result;
        // }
        function convertTree(tree) {
            var result = []; // 遍历 tree

            tree.forEach(function (item) {
                // 解构赋值
                var value = item.code,
                    label = item.name,
                    children = item.children; // 如果有子节点，递归

                if (children) {
                children = convertTree(children);
                }

                result.push({
                value: value,
                label: label,
                children: children
                });
            });
            return result;
        }
        // 获取级联选择器数据
        // 递归方法
        function getTreeData(data) {
            // 循环遍历json数据
            for(var i=0;i<data.length;i++) {
                if(data[i].children == undefined) {
                    // children若为空数组，则将children设为undefined
                    data[i].children = [];
                } else {
                    // children若不为空数组，则继续 递归调用 本方法
                    // this.getTreeData(data[i].children);
                    getTreeData(data[i].children);
                }
            }
            return data;
        }
        //省市级联
        function cascader(id1,class1,id2,id3,value) {
            layui.config({
                base: "js/lay/mymodules/"
            }).use(['form',"jquery","cascader","form"], function() {
                var cascader = layui.cascader;
                var cas = cascader({
                    elem: id1,
                    data: value,
                    success: function (valData,labelData) {
                        verifyAddress(id1,class1);
                        labelData = labelData.join('');
                        $(id2).val(labelData + $(id3).val())
                        $(id3).blur(function () {
                            $(id2).val(labelData + $(id3).val())
                        })
                    }
                });
            });
        }
    $('.content').load('PublicOrder.html',function(){
        /*=======快速寄件模块=======*/
        var djxd_p1 = new Promise(function(resolve, reject) {
            $.get('js/pcas-code.json', function(data) {
                data = convertTree(data);
                data = getTreeData(data);
                resolve(data);
                console.log(data);
            }) 
        })

        //通过event.persisted和window.performance判断页面是否为后退进入
        window.addEventListener('pageshow', function (event) {
            if(event.persisted || window.performance && window.performance.navigation.type == 2) {
                // location.refresh();   //此处可以写你的实际应用的代码
                window.location.reload();
            }
        },false);

        //自定义方法:中文为两个字符
        $.validator.addMethod("stringMaxLength",function(value,element,params) {
            var length = value.length;
            for(var i = 0; i < value.length; i++) {
                if(value.charCodeAt(i) > 19967) {
                    length++;
                }
            }
            return length>params[0]?false:true;
        });

        //自定义手机号/固定电话验证方法
        $.validator.addMethod("jiJianRenDianHua",function(val) {
                if (val!==""){
                    //val:自动获得当前正在验证的元素的内容
                    var reg = /^(0[0-9]{2,3}\-)([2-9][0-9]{6,7})+(\-[0-9]{1,4})?|1[34589]\d{9}$/;
                    return reg.test(val);
                } else return true;
            },
            "您输入的号码格式不正确，请重新输入"
        );

        //单件下单
        $(function() {
            //自定义固定电话验证方法
            $.validator.addMethod("shouJianRenDianHua", function(val) {
                    if (val!=="") {
                        //val:自动获得当前正在验证的元素的内容
                        var reg = /^(0[0-9]{2,3}\-)([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$/;
                        return reg.test(val);
                    } else return true;
                },
                "您输入的电话号码格式不正确，请重新输入"
            );
            $("#TaxPayment input").click(function(){
                console.log($("#TaxPayment input[value='2']").is(':checked'));
                
                if($("#TaxPayment input[value='2']").is(':checked')){
                    $("#PayTaxes").show();
                }else{
                    $("#PayTaxes").hide();
                }
            })
            //自定义手机号验证方法
            $.validator.addMethod("shouJianRenShouJi", function(val) {
                    if (val!=="") {
                        //val:自动获得当前正在验证的元素的内容
                        var reg=/^1[34589]\d{9}$/;
                        return reg.test(val);
                    } else return true;
                },
                "您输入的手机号码格式不正确，请重新输入"
            );
            
            //验证单件下单表单
            $("#form1").validate({
                rules: {
                    jiJianRenMingCheng: {
                        required: true,
                        stringMaxLength:["20"]
                    }, 
                    jiJianGongSiMingCheng: {
                        required: true,
                        stringMaxLength:["20"]
                    }, 
                    jiJianRenDianHua: {
                        required: true,
                        jiJianRenDianHua:true
                    }, 
                    jiJianRenDiZhi1: {
                        required: true,
                        minlength:12
                    }, 
                    shouJianRenXingMing: {
                        required: true,
                        stringMaxLength:["20"]
                    }, 
                    shouJianRenGongSi: {
                        required: true,
                        stringMaxLength:["20"]
                    }, 
                    shouJianRenShouJi: {
                        required: true,
                        shouJianRenShouJi:true
                    }, 
                    shouJianRenDianHua: {
                        required: true,
                        shouJianRenDianHua:true
                    }, 
                    guoJia: "required",
                    shouJianRenYouBian: {
                        required: true,
                        digits:true
                    }, 
                    shouJianRenChengShi: "required",
                    zhouMing: {
                        required: true,
                        stringMaxLength:["30"]
                    }, 
                    shouJianRenDiZhi1: {
                        required: true,
                        stringMaxLength:["35"]
                    }, 
                    shouJianRenDiZhi2: {
                        required: true,
                        stringMaxLength:35
                    }, 
                    shouJianRenDiZhi3: {
                        required: true,
                        stringMaxLength:35
                    }, 
                    baoGuanFangShi: "required",
                    baoGuoLeiXing: "required",
                    fuShuiJin: "required",
                    wuLiuFangShi: "required",
                    requiredZhuanDanFaPiao: "required",
                    requiredZhuanDanLabel: "required",
                    companyTaxNo: "required",
                    'daiShouHuoKuan:number': "required",
                    daiShouHuoKuanBiZhong: "required",
                    'danJianList[[chang]]:number': {
                        // required: true,
                        digits:true,
                        max: 10000
                    }, 
                    'danJianList[[kuan]]:number': {
                        // required: true,
                        digits:true,
                        max: 10000
                    }, 
                    'danJianList[[gao]]:number': {
                        // required: true,
                        digits:true,
                        max: 10000
                    }, 
                    'danJianList[[shiZhong]]:number': {
                        required: true,
                        digits:true,
                        max: 10000
                    }, 
                    destinationSuburb: {
                        // required: true,
                        stringMaxLength:20
                    }, 
                    eori: {
                        // required: true,
                        stringMaxLength:100
                    }, 
                    haiYunDanHao: "required",
                    // huoWuTeXing: "required",
                    'jianShu:number': {
                        required: true,
                        digits:true,
                        max:100000
                    }, 
                    keHuDanHao: {
                        required: true,
                        stringMaxLength:30
                    }, 
                    kongYunDanHao: "required",
                    maiJiaId: "required",
                    qiTaDanHao1: {
                        // required: true,
                        stringMaxLength:30
                    }, 
                    qiTaDanHao2: "required",
                    remark: {
                        // required: true,
                        stringMaxLength:100
                    }, 
                    'shenBaoXinXiList[[caiZhiCn]]': {
                        // required: true,
                        stringMaxLength:30
                    }, 
                    'shenBaoXinXiList[[caiZhiEn]]': {
                        required: true,
                        stringMaxLength:30
                    }, 
                    'shenBaoXinXiList[[cargoModel]]': {
                        // required: true,
                        stringMaxLength:30
                    }, 
                    'shenBaoXinXiList[[originName]]': {
                        // required: true,
                        stringMaxLength:30
                    }, 
                    'shenBaoXinXiList[[salesUrl]]': {
                        // required: true,
                        stringMaxLength:100
                    }, 
                    'shenBaoXinXiList[[shenBaoBiZhong]]': {
                        required: true,
                        stringMaxLength:10
                    }, 
                    'shenBaoXinXiList[[shenBaoDanJia]]:number': {
                        required: true,
                        digits:true,
                        max: 1000000
                    }, 
                    'shenBaoXinXiList[[shenBaoHaiGuanBianMa]]': {
                        required: true,
                        minlength: 6,
                        stringMaxLength:30
                    }, 
                    'shenBaoXinXiList[[shenBaoJinE]]:number': {
                        // required: true,
                        // digits:true,
                        max: 1000000
                    }, 
                    'shenBaoXinXiList[[shenBaoPinMing]]': {
                        required: true,
                        stringMaxLength:30
                    }, 
                    'shenBaoXinXiList[[shenBaoShuLiang]]:number': {
                        required: true,
                        digits:true,
                        max:1000000
                    }, 
                    'shenBaoXinXiList[[sku]]': {
                        // required: true,
                        stringMaxLength:30
                    }, 
                    'shenBaoXinXiList[[tradeMark]]': {
                        // required: true,
                        stringMaxLength:30
                    }, 
                    'shenBaoXinXiList[[unit]]': {
                        // required: true,
                        stringMaxLength: 10
                    }, 
                    'shenBaoXinXiList[[unitGrossWeight]]:number': {
                        // required: true,
                        digits:true,
                        max: 1000000
                    }, 
                    // 'shenBaoXinXiList[[unitNetWeight]]:number': "required",
                    'shenBaoXinXiList[[yongTuCn]]': {
                        // required: true,
                        stringMaxLength:30
                    }, 
                    'shenBaoXinXiList[[yongTuEn]]': {
                        required: true,
                        stringMaxLength:30
                    }, 
                    'shenBaoXinXiList[[zhongWenPinMing]]': {
                        // required: true,
                        stringMaxLength:30
                    }, 
                    'shouHuoCaiJi:number': {
                        required: true,
                        digits:true,
                        max:10000
                    }, 
                    shouHuoQuDao: "required",
                    'shouHuoShiZhong:number': {
                        // required: true,
                        digits:true,
                        max:10000
                    }, 
                    thirdPartyTaxPaymentAccount: {
                        required: true,
                        stringMaxLength:35
                    }, 
                    zhongWenPingMing: {
                        // required: true,
                        stringMaxLength:30
                    }, 
                },
                messages: {
                    jiJianRenMingCheng: { 
                        required: "请输入寄件人的名字",
                        stringMaxLength: "最多可输入20个字符"
                    },
                    jiJianGongSiMingCheng: { 
                        required: "请输入寄件人的公司名称",
                        stringMaxLength: "最多可输入20个字符"
                    },
                    jiJianRenDianHua: { 
                        required: "请输入寄件人的电话",
                    },
                    jiJianRenDiZhi1: { 
                        required: "请输入寄件人所在街道及详细地址",
                        minlength: "详细地址最少输入24个字符，请重新输入！"
                    },
                    shouJianRenXingMing: { 
                        required: "请输入收件人的名字",
                        stringMaxLength: "最多可输入20个字符"
                    },
                    shouJianRenGongSi: { 
                        required: "请输入收件人的公司名称",
                        stringMaxLength: "最多可输入20个字符"
                    },
                    shouJianRenShouJi: { 
                        required: "请输入收件人的手机号码",
                    },
                    shouJianRenDianHua: { 
                        required: "请输入收件人的电话号码",
                    },
                    guoJia: "请选择收件人的国家",
                    shouJianRenYouBian: { 
                        required: "请输入收件人的邮编",
                        digits: "邮编号码格式不正确，请重新输入"
                    },
                    shouJianRenChengShi: "请输入收件人的城市",
                    zhouMing: { 
                        required: "请输入收件人的省份/洲名",
                        stringMaxLength: "最大长度不能超过30个字符,一个汉字为两个字符"
                    },
                    shouJianRenDiZhi1: { 
                        required: "请输入收件人的地址一",
                        stringMaxLength: "最大长度不能超过35个字符,一个汉字为两个字符"
                    },
                    shouJianRenDiZhi2: { 
                        required: "请输入收件人的地址二",
                        stringMaxLength: "最大长度不能超过35个字符,一个汉字为两个字符"
                    },
                    shouJianRenDiZhi3: { 
                        required: "请输入收件人的地址三",
                        stringMaxLength: "最大长度不能超过35个字符,一个汉字为两个字符"
                    },
                    baoGuanFangShi: "请选择报关方式",
                    baoGuoLeiXing: "请选择包裹类型",
                    fuShuiJin: "请选择付税金方式",
                    wuLiuFangShi: "请选择物流方式",
                    requiredZhuanDanFaPiao: "请选择是否需要返回转单发票",
                    requiredZhuanDanLabel: "请选择是否需要返回转单label",
                    companyTaxNo: "请填写公司税号",
                    'daiShouHuoKuan:number': "请填写代收货款",
                    daiShouHuoKuanBiZhong: "请填写代收货款币种",
                    'danJianList[[chang]]:number': { 
                        required: "请填写包裹的长度",
                        digits: "格式不正确，请重新输入",
                        max: "超出范围，请重新输入"
                    },
                    'danJianList[[kuan]]:number': { 
                        required: "请填写包裹的宽度",
                        digits: "格式不正确，请重新输入",
                        max: "超出范围，请重新输入"
                    },
                    'danJianList[[gao]]:number': { 
                        required: "请填写包裹的高度",
                        digits: "格式不正确，请重新输入",
                        max: "超出范围，请重新输入"
                    },
                    'danJianList[[shiZhong]]:number': { 
                        required: "请填写包裹的重量",
                        digits: "格式不正确，请重新输入",
                        max: "超出范围，请重新输入"
                    },
                    destinationSuburb: { 
                        required: "请填写郊区名",
                        stringMaxLength: "最多可输入20个字符"
                    },
                    eori:  { 
                        required: "请填写EORI号码",
                        stringMaxLength: "最大长度不能超过30个字符,一个汉字为两个字符"
                    }, 
                    haiYunDanHao: "请填写海运单号",
                    huoWuTeXing: "请选择货物特性",
                    'jianShu:number': { 
                        required: "请填写件数",
                        digits: "格式不正确，请重新输入",
                        max: "超出范围，请重新输入"
                    },
                    keHuDanHao:  { 
                        required: "请输入客户单号",
                        stringMaxLength: "最大长度不能超过30个字符,一个汉字为两个字符"
                    },
                    kongYunDanHao: "请输入空运单号",
                    maiJiaId: "请输入买家ID",
                    qiTaDanHao1: { 
                        required: "请输入其他单号1",
                        stringMaxLength: "最大长度不能超过30个字符,一个汉字为两个字符"
                    },
                    qiTaDanHao2: "请输入其他单号2",
                    remark: { 
                        required: "请填写备注",
                        stringMaxLength: "最大长度不能超过100个字符,一个汉字为两个字符"
                    },
                    'shenBaoXinXiList[[caiZhiCn]]': { 
                        required: "请输入申报中文材质",
                        stringMaxLength: "最大长度不能超过30个字符,一个汉字为两个字符"
                    },
                    'shenBaoXinXiList[[caiZhiEn]]': { 
                        required: "请输入申报英文材质",
                        stringMaxLength: "最大长度不能超过30个字符,一个汉字为两个字符"
                    },
                    'shenBaoXinXiList[[cargoModel]]': { 
                        required: "请输入商品型号",
                        stringMaxLength: "最大长度不能超过30个字符,一个汉字为两个字符"
                    },
                    'shenBaoXinXiList[[originName]]': { 
                        required: "请输入原产地",
                        stringMaxLength: "最大长度不能超过30个字符,一个汉字为两个字符"
                    },
                    'shenBaoXinXiList[[salesUrl]]': { 
                        required: "请输入销售链接",
                        stringMaxLength: "最大长度不能超过100个字符,一个汉字为两个字符"
                    },
                    'shenBaoXinXiList[[shenBaoBiZhong]]': { 
                        required: "请输入销售链接",
                        stringMaxLength: "最大长度不能超过10个字符,一个汉字为两个字符"
                    },
                    'shenBaoXinXiList[[shenBaoDanJia]]:number': { 
                        required: "请输入申报单价",
                        digits: "格式不正确，请重新输入",
                        max: "超出范围，请重新输入"
                    },
                    'shenBaoXinXiList[[shenBaoHaiGuanBianMa]]': { 
                        required:  "请输入申报海关编码",
                        minlength: "最小长度不能低于6个字符,一个汉字为两个字符",
                        stringMaxLength: "最大长度不能超过30个字符,一个汉字为两个字符"
                    },
                    'shenBaoXinXiList[[shenBaoJinE]]:number': { 
                        required: "请输入申报总价",
                        digits: "格式不正确，请重新输入",
                        max: "超出范围，请重新输入"
                    },
                    'shenBaoXinXiList[[shenBaoPinMing]]': { 
                        required: "请输入申报品名",
                        stringMaxLength: "最大长度不能超过30个字符,一个汉字为两个字符"
                    },
                    'shenBaoXinXiList[[shenBaoShuLiang]]:number': { 
                        required: "请输入申报数量",
                        digits: "格式不正确，请重新输入",
                        max: "超出范围，请重新输入"
                    },
                    'shenBaoXinXiList[[sku]]': { 
                        required: "请输入SKU",
                        stringMaxLength: "最大长度不能超过30个字符,一个汉字为两个字符"
                    },
                    'shenBaoXinXiList[[tradeMark]]': { 
                        required: "请输入品牌",
                        stringMaxLength: "最大长度不能超过30个字符,一个汉字为两个字符"
                    },
                    'shenBaoXinXiList[[unit]]': { 
                        required: "请输入单位 ",
                        stringMaxLength: "最大长度不能超过10个字符,一个汉字为两个字符"
                    },
                    'shenBaoXinXiList[[unitGrossWeight]]:number': { 
                        required: "请输入商品毛重",
                        digits: "格式不正确，请重新输入",
                        max: "超出范围，请重新输入"
                    },
                    'shenBaoXinXiList[[unitNetWeight]]:number': "请输入商品净重",
                    'shenBaoXinXiList[[yongTuCn]]': { 
                        required: "请填写申报中文用途",
                        stringMaxLength: "最大长度不能超过10个字符,一个汉字为两个字符"
                    },
                    'shenBaoXinXiList[[yongTuEn]]': { 
                        required: "请填写申报英文用途",
                        stringMaxLength: "最大长度不能超过10个字符,一个汉字为两个字符"
                    },
                    'shenBaoXinXiList[[zhongWenPinMing]]': { 
                        required: "请填写中文品名",
                        stringMaxLength: "最大长度不能超过30个字符,一个汉字为两个字符"
                    },
                    'shouHuoCaiJi:number': { 
                        required: "请输入收货材积重",
                        digits: "格式不正确，请重新输入",
                        max: "超出范围，请重新输入"
                    },
                    shouHuoQuDao: "请输入收货渠道",
                    'shouHuoShiZhong:number': { 
                        required: "请输入收货实重",
                        digits: "格式不正确，请重新输入",
                        max: "超出范围，请重新输入"
                    },
                    thirdPartyTaxPaymentAccount: { 
                        required: "请输入第三方付税金账号",
                        stringMaxLength: "最多可输入35个字符"
                    },
                    zhongWenPingMing: { 
                        required: "请填写中文品名",
                        stringMaxLength: "最大长度不能超过30个字符,一个汉字为两个字符"
                    },
                }
            });
            
            currentTabIndex = getCurrentTabIndex("#rootwizard");
            //判断tab标签索引
            if (currentTabIndex == 0) {
                $(".previous").hide();
            }
            //为next绑定单击事件
            $(".djxd .next a").click(function() {
                var $valid = $("#form1").valid();
                //将HTML表单序列化为js对象
                json = $('#form1').serializeJSON();
                //将js对象转换成一维数组包对象
                json2 = [];
                json2.push(json);
                console.log($valid);
                console.log(PCD);
                console.log(jjdz11);
                console.log(json);
                console.log(json2);
                //获取token
                token = sessionStorage.getItem("token");
                //获取当前下标
                currentTabIndex = getCurrentTabIndex("#rootwizard");
                if($valid && PCD && jjdz11) {
                    if(currentTabIndex == 2 && !($(".protocol input[type='checkbox']").is(':checked'))) {
                        $('#rootwizard li:eq('+(currentTabIndex)+') a').tab('show');
                        layer.msg('请勾选《违禁产品声明》');
                        // layer.msg('请勾选《违禁产品声明》',);
                    } else if (currentTabIndex == 2 && $(".protocol input[type='checkbox']").is(':checked')) {
                        if(token == '' || token == 'undefined' || token == undefined || token == NaN || token == 'NaN') {
                            //填充step4信息
                            lastStep("#rootwizard",".show_phone3",currentTabIndex);
                            //禁用下一步按钮
                            disable(".djxd",true,"none",0.2);
                            //弹出iframe登录框
                            loginBox();
                        }else{
                            lastStep("#rootwizard",".show_phone3",currentTabIndex);
                            disable(".djxd",true,"none",0.2);
                            yundans(json2,"#rootwizard",currentTabIndex,".djxd")
                        }
                    }else{
                        $(".djxd .previous").show();
                        $('#rootwizard li:eq('+(currentTabIndex+1)+') a').tab('show');
                    }
                }
            })
            //为previous绑定单击事件
            $(".djxd .previous").click(function() {
                previous("#rootwizard",".djxd .previous")
            })
            /*=========step1=========*/
            //省市区验证
            $(".djxd .next").click(function() {
                verifyAddress("#a",".PCD");
                verifyAddress("#jiJianRenDiZhi1",".jjdz11");
            })
            
            $("#jiJianRenDiZhi1").keyup(function() {
                verifyAddress("#jiJianRenDiZhi1",".jjdz11")
            })

            $(".PCD .urp-cascader-content").on("focus",function() {
                verifyAddress("#a",".PCD");
            });

            djxd_p1.then(function(value) {
                cascader("#a",".PCD","#jiJianRenDiZhi10","#jiJianRenDiZhi1",value);
            })
            /*=========step2=========*/
            var datas;
            var States;
            //获取邮编
            function postcode() {
                var us = $("#countryId").val();
                var state = $("#stateId").val();
                var city = $("#cityId").val();
                console.log("http://api.zippopotam.us/" + us + "/" + state + "/" + city);
                $.get("http://api.zippopotam.us/" + us + "/" + state + "/" + city, function(data) {
                    $("#shouJianRenYouBian").attr("value",data.places[0]["post code"]);
                })
            }

            //获取国家，洲/省，城市
            // $.get('js/countries+states+cities.json', function(data) {
            //     datas = data;
            //     var countriesOptions = '';
                
            //     for(var i = 0;i<data.length;i++) {
            //         countriesOptions += '<option id=' + data[i].id + " value=" + data[i].iso2 +'>' + data[i].name + '</option>';
            //     };
            //     // console.log(countriesOptions);
            //     $("#countryId").append(countriesOptions);
            //     // for(var i = 0;i<data.length;i++) {
            //     //     $("#countryId").append('<option id=' + data[i].id + " value=" + data[i].iso2 +'>' + data[i].name + '</option>');
            //     // };
            // })

            $.post('https://geodata.solutions/api/api.php?type=getCountries',function(data){
                // console.log(data.result);
                // console.log(Object.keys(data.result));
                var countriesOptions = '';
                for (let key of Object.keys(data.result)) {
                    let mealName = data.result[key];
                    countriesOptions += '<option value=' + key +'>' + mealName + '</option>';
                }
                $("#countryId").append(countriesOptions);
            })


            // $("#countryId").change(function() {
            //     var j = $("#countryId option:selected").attr('id');
            //     j = j-1;
            //     var StateOptions = '';
            //     $("#stateId").html("");  //先清空再赋值
            //     States = datas[j].states;
            //     console.log(States);
            //     for(var i = 0;i<States.length;i++) {
            //         StateOptions += '<option id=' + States[i].id + " value=" + States[i].state_code +'>' + States[i].name + '</option>'; 
            //     };
            //     $("#stateId").append(StateOptions);
            // })

            $("#countryId").change(function() {
                console.log($("#countryId").val());
                $.post('https://geodata.solutions/api/api.php?type=getStates&countryId=' + $("#countryId").val(),function(data){
                    console.log(data);
                    var StateOptions = '';
                    $("#stateId").html("");  //先清空再赋值
                    for (let key of Object.keys(data.result)) {
                        let mealName = data.result[key];
                        StateOptions += '<option value=' + key +'>' + mealName + '</option>';
                    }
                    $("#stateId").append(StateOptions);
                })
            })

            // $("#stateId").change(function() {
            //     var k; 
            //     var data= States.filter(function(item) {
            //         k= $("#stateId option:selected").attr('id');
            //         return item.id == k; 
            //     })
            //     $("#cityId").html("");  //先清空再赋值
            //     var Cities = data[0].cities;
            //     var CitieOptions = '';
            //     for(var i = 0;i<Cities.length;i++) {
            //         CitieOptions += '<option id=' + Cities[i].id + '>' + Cities[i].name + '</option>';
            //     };
            //     $("#cityId").append(CitieOptions);
            //     postcode();
            // })
            $("#stateId").change(function() {
                $.post('https://geodata.solutions/api/api.php?type=getCities&countryId=' + $("#countryId").val() + '&stateId=' + $("#stateId").val(),function(data){
                    console.log(data);
                    var CitieOptions = '';
                    $("#cityId").html("");  //先清空再赋值
                    for (let key of Object.keys(data.result)) {
                        let mealName = data.result[key];
                        CitieOptions += '<option id=' + key +'>' + mealName + '</option>';
                    }
                    $("#cityId").append(CitieOptions);
                    // postcode();
                })
                // var k; 
                // var data= States.filter(function(item) {
                //     k= $("#stateId option:selected").attr('id');
                //     return item.id == k; 
                // })
                // $("#cityId").html("");  //先清空再赋值
                // var Cities = data[0].cities;
                // var CitieOptions = '';
                // for(var i = 0;i<Cities.length;i++) {
                //     CitieOptions += '<option id=' + Cities[i].id + '>' + Cities[i].name + '</option>';
                // };
                // $("#cityId").append(CitieOptions);
                // postcode();
            })
            // $("#cityId").change(function() {
            //     postcode();
            // })

            /*=========step3=========*/
            //multiple-select多选插件
            $('.multiple-select').multipleSelect();

            //获取货物特性的值
            $("#huoWuTeXing").change(function() {
                $('.hwtx').val($(this).val()?$(this).val().join(','):'');
                console.log($(".hwtx").val());
                console.log($('#huoWuTeXing').val());  
            });

            //ajax动态获取收货渠道
            var p1 = new Promise(function(resolve, reject) {
                ajax2('get', '/getReceivingChannels', '', 'json', function (data) {
                    if (data.statusCode == 200) {
                        resolve(data.data.length);
                        $("#shouHuoQuDao").html("");
                        for (var i = 0; i < data.data.length; i++) {
                            $("#shouHuoQuDao").append("<option value='"+data.data[i].channelName+"'>"+data.data[i].channelName+"</option>");
                        }
                    }
                })
            })
            p1.then(function(value) {
                $('.select2').select2();
            })

            //申报总价 = 申报数量 * 申报单价
            var inputs = $("#form1 .table>tbody>tr>td>input[class*=add]");
            for(i=0;i<inputs.length;i++) {
                inputs[i].onblur = function() {
                    var add1 = $(".add1").val();
                    var add2 = $(".add2").val();
                    $(".addSum").val((add1*add2).toFixed(3));
                    console.log(inputs.length);
                }
            }

            $(".content").on("click",".protocol a",function(){
                orderTerms(".protocol");
            })
            // $(".protocol a").click(function() {
            //     orderTerms(".protocol");
            // })
        })

        //批量下单
        $(function() {
            //验证批量下单表单
            $("#form2").validate({
                rules: {
                    jiJianRenMingCheng: {
                        required: true,
                        stringMaxLength:["20"]
                    }, 
                    jiJianGongSiMingCheng: {
                        required: true,
                        stringMaxLength:["20"]
                    }, 
                    jiJianRenDianHua: {
                        required: true,
                        jiJianRenDianHua:true
                    }, 
                },
                messages: {
                    jiJianRenMingCheng: { 
                        required: "请输入寄件人的名字",
                        stringMaxLength: "最多可输入20个字符"
                    },
                    jiJianGongSiMingCheng: { 
                        required: "请输入寄件人的公司名称",
                        stringMaxLength: "最多可输入20个字符"
                    },
                    jiJianRenDianHua: { 
                        required: "请输入寄件人的电话",
                    },
                }
            });
            //文件流转BinaryString
            // function fixedData(data) {
            //     let o = ''
            //     let l = 0
            //     const w = 10240
            //     for (; l < data.byteLength / w; ++l) o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w,l * w + w)))
            //     o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w)))
            //     return o
            // }
            function fixedData(data) {
                var o = '';
                var l = 0;
                var w = 10240;
                for (; l < data.byteLength / w; ++l)
                o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w, l * w + w)));
                o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w)));
                return o;
            }
            //批量修改数组对象属性名
            function convertKey(arr, key) {
                var newArr = [];
                arr.forEach(function(item, index) {
                    var newObj = {};
                    for (var i = 0; i < key.length; i++) {
                        newObj[key[i]] = item[Object.keys(item)[i]]
                    }
                    newArr.push(newObj);
                })
                return newArr;
            }
            //Excel数据转换为json格式
            function importf(obj) {
                var reader = new FileReader();
                return new Promise(function(resolve, reject) {
                    if(obj.files[0].type !== "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") {
                        layer.msg('文件类型不正确');
                        return false;
                    }else if(obj.files[0].name !== "D制单导入预报示例.xlsx"){
                        layer.msg('模板导入错误，请勿随意更改模板命名！');
                        return false;
                    }
                    if (!obj.files) {
                        return;
                    }
                    var f = obj.files[0];
                    reader.readAsArrayBuffer(f);
                    reader.onload = function(e) {
                        var data = e.target.result;
                        var wb = XLSX.read(btoa(fixedData(data)), { type: 'base64' });//XLSX.read()以二进制流方式读取excel数据；btoa() 函数能够从二进制数据“字符串”创建一个base-64编码的ASCII字符串。
                        var obj = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]], {defval:""});//wb.SheetNames[0]是获取Sheets中第一个Sheet的名字;wb.Sheets[Sheet名]获取第一个Sheet的数据
                        if(wb.SheetNames[0] == "运单"){
                            resolve(obj);
                            document.getElementById("excel").innerHTML = XLSX.utils.sheet_to_html(wb.Sheets[wb.SheetNames[0]], {defval:"", header:  "", footer: ""  });//XLSX.utils.sheet_to_json方法解析表格对象返回相应的JSON数据
                            console.log( JSON.stringify(XLSX.utils.sheet_to_html(wb.Sheets[wb.SheetNames[0]], {defval:"", header:  "", footer: ""  })));
                            $("#two2 table>tbody>tr>td").append("<div style='width:80px;'></div>");
                        }else{
                            layer.msg('模板导入错误，请勿随意更改模板！');
                            return false;
                        }
                    };
                })
            }
            //json数据处理成后端接口数据格式
            function dataProcess(obj) {
                return new Promise(function(resolve,reject) {
                    for(var i=0;i<obj.length;i++) {
                        delete obj[i].公司名称;
                        var keysArr = Object.keys(obj[i]);
                    }
                    var data1 = convertKey(obj, ['shouJianRenXingMing', 'shouJianRenGongSi', 'shouJianRenShouJi', 'shouJianRenDianHua', 'guoJia', 'zhouMing', 'shouJianRenChengShi', 'shouJianRenYouBian', 'shouJianRenDiZhi1', 'shouJianRenDiZhi2', 'shouJianRenDiZhi3', 'baoGuanFangShi', 'baoGuoLeiXing', 'fuShuiJin', 'wuLiuFangShi', 'keHuDanHao', 'huoWuTeXing', 'shouHuoQuDao', 'qiTaDanHao1', 'jianShu', 'shouHuoCaiJi', 'shouHuoShiZhong', 'destinationSuburb', 'thirdPartyTaxPaymentAccount', 'eori', 'zhongWenPingMing', 'remark', 'chang', 'kuan', 'gao', 'shiZhong', 'caiZhiCn', 'caiZhiEn', 'cargoModel', 'originName', 'salesUrl', 'shenBaoBiZhong', 'shenBaoDanJia', 'shenBaoHaiGuanBianMa', 'shenBaoJinE', 'shenBaoPinMing', 'shenBaoShuLiang', 'sku', 'tradeMark', 'unit', 'unitGrossWeight', 'unitNetWeight', 'yongTuCn', 'yongTuEn', 'zhongWenPinMing']);
                    var shenBaoXinXiList = ['caiZhiCn', 'caiZhiEn', 'cargoModel', 'originName', 'salesUrl', 'shenBaoBiZhong', 'shenBaoDanJia', 'shenBaoHaiGuanBianMa', 'shenBaoJinE', 'shenBaoPinMing', 'shenBaoShuLiang', 'sku', 'tradeMark', 'unit', 'unitGrossWeight', 'unitNetWeight', 'yongTuCn', 'yongTuEn', 'zhongWenPinMing'];
                    var danJianList = ['chang', 'kuan', 'gao', 'shiZhong'];
                    var string = ['companyTaxNo', 'daiShouHuoKuanBiZhong', 'destinationSuburb', 'eori', 'guoJia', 'haiYunDanHao', 'huoWuTeXing', 'keHuDanHao', 'kongYunDanHao', 'qiTaDanHao1', 'qiTaDanHao2', 'remark', 'shouHuoQuDao', 'shouJianRenChengShi', 'shouJianRenDiZhi1' ,'shouJianRenDiZhi2', 'shouJianRenDiZhi3', 'shouJianRenDianHua', 'shouJianRenGongSi', 'shouJianRenShouJi', 'shouJianRenXingMing', 'shouJianRenYouBian', 'thirdPartyTaxPaymentAccount', 'zhongWenPingMing', 'zhouMing', 'caiZhiCn', 'caiZhiEn', 'cargoModel', 'originName', 'salesUrl', 'shenBaoBiZhong', 'shenBaoHaiGuanBianMa', 'shenBaoPinMing', 'sku', 'taxCode', 'tradeMark', 'unit', 'yongTuCn', 'yongTuEn', 'zhongWenPinMing'];
                    var number = ['daiShouHuoKuan', 'shouHuoCaiJi', 'shouHuoShiZhong', 'chang', 'gao', 'kuan', 'shiZhong', 'shenBaoDanJia', 'shenBaoJinE', 'unitGrossWeight', 'unitNetWeight', 'shenBaoShuLiang', 'jianShu'];
                    var integer = ['baoGuanFangShi', 'baoGuoLeiXing', 'fuShuiJin', 'wuLiuFangShi'];
                    var data2 = [];
                    var data3 = [];
                    for(var i=0;i<data1.length;i++) {
                        var obj1 = {};  
                        var arr1 = [];
                        var obj2 = {};
                        var obj3 = {};
                        var arr2 = [];
                        Object.keys(data1[i]).forEach(function(key) {
                            if(danJianList.includes(key)) {  
                                obj2[key]=parseFloat(data1[i][key]);
                                arr1[0]=obj2;
                                obj1["danJianList"]=arr1;
                            } else if (shenBaoXinXiList.includes(key)) {
                                if(number.includes(key)) {
                                    obj3[key]=parseFloat(data1[i][key]);
                                } else {
                                    obj3[key]=(data1[i][key]).toString();
                                }
                                arr2[0]=obj3;
                                obj1["shenBaoXinXiList"]=arr2;
                            } else {
                                if(number.includes(key)) {
                                    obj1[key]=parseFloat(data1[i][key]);
                                } else if (integer.includes(key)) {
                                    if(key=="baoGuanFangShi") {
                                        obj1[key] =  ['一般普货', '一般贸易'].indexOf(data1[i][key]);
                                    }else if(key=="baoGuoLeiXing") {
                                        obj1[key] =  ['文件', '包裹', '包裹袋'].indexOf(data1[i][key]);
                                    }else if(key=="fuShuiJin") {
                                        obj1[key] =  ['收件人', '寄件人', '第三方'].indexOf(data1[i][key]);
                                    }else if(key=="wuLiuFangShi") {
                                        obj1[key] =  ['快递', '小包', '专线', 'EMS', '空运'].indexOf(data1[i][key]);
                                    }
                                } else {
                                    obj1[key]=(data1[i][key]).toString();
                                }
                            }
                        })
                        data2.push(obj1);
                    }
                    data2.map(function(value, index, array) {
                        var obj4 = $.extend({},value,json22[0])
                        data3 = data3.concat(obj4)
                    });
                    resolve(data3);
                })
            }
            
            $(".plxd #next").click(function() {
                //验证批量下单表单数据
                var $valid2 = $("#form2").valid();
                currentTabIndex2 = getCurrentTabIndex("#rootwizard2");
                json22 = [{
                            "jiJianGongSiMingCheng": $("#jiJianGongSiMingCheng2").val(),
                            "jiJianRenDiZhi1": $("#jiJianRenDiZhi100").val(),
                            "jiJianRenDiZhi2": $("#jiJianRenDiZhi22").val(),
                            "jiJianRenDiZhi3": $("#jiJianRenDiZhi33").val(),
                            "jiJianRenDianHua": $("#jiJianRenDianHua2").val(),
                            "jiJianRenMingCheng": $("#jiJianRenMingCheng2").val(),
                }]   
                console.log(json22)
                console.log($valid2);
                console.log(currentTabIndex2);
                //获取token
                token = sessionStorage.getItem("token");
                if($valid2 && PCD2 && jjdz12) {
                    if(currentTabIndex2 == 1 && !($(".protocol2 input[type='checkbox']").is(':checked'))) {
                        $('#rootwizard2 li:eq('+(currentTabIndex2)+') a').tab('show');
                        layer.msg('请勾选《违禁产品声明》');
                        // layer.msg('请勾选《违禁产品声明》',);
                    } else if (currentTabIndex2 == 1 && $(".protocol2 input[type='checkbox']").is(':checked')) {
                        if(token == '' || token == 'undefined' || token == undefined || token == NaN || token == 'NaN') {
                            lastStep("#rootwizard2",".show_phone33",currentTabIndex2);
                            disable(".plxd",true,"none",0.2);
                            //弹出iframe登录框
                            loginBox();
                        }else{
                            lastStep("#rootwizard2",".show_phone33",currentTabIndex2);
                            disable(".plxd",true,"none",0.2);
                            yundans(newdata,"#rootwizard2",currentTabIndex2,".plxd");
                        }
                    }else{
                        currentTabIndex2 = getCurrentTabIndex("#rootwizard2");
                        $(".plxd .previous").show();
                        $('#rootwizard2 li:eq('+(currentTabIndex2+1)+') a').tab('show');
                    }
                }
            })
            //上一步
            $(".plxd #previous").click(function() {
                previous("#rootwizard2",".plxd #previous");
            })
            //上传excel数据转换成接口格式
            if (currentTabIndex2 == 0) {
                $(".plxd #previous").hide();
            }
            
            /*=========step1=========*/
            //省市区验证
            $(".plxd .next").click(function() {
                verifyAddress("#b",".PCD2");
                verifyAddress("#jiJianRenDiZhi111",".jjdz12")
            })

            $(".PCD2 .urp-cascader-content").on("focus",function() {
                verifyAddress("#b",".PCD2");
            });

            $("#jiJianRenDiZhi111").keyup(function() {
                verifyAddress("#jiJianRenDiZhi111",".jjdz12")
            })
            
            djxd_p1.then(function(value) {
                cascader("#b",".PCD2","#jiJianRenDiZhi100","#jiJianRenDiZhi111",value);
            })
            /*=========step2=========*/
            $("[type='file']").change(function() {
                importf(this)
                .then(dataProcess)
                .then(function (data){
                    newdata = data;
                    console.log(data);
                });
                $("[type='file']").val("");
            })

            $(".protocol2 a").click(function(){
                orderTerms(".protocol2");
            })    
        })
    });
